package cn.craftyun.yunexam.mapper;

import cn.craftyun.yunexam.entity.ExamAnswer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface ExamAnswerMapper extends BaseMapper<ExamAnswer> {
    @Update("DELETE FROM exam_answer WHERE exam_id IN (SELECT id FROM exam WHERE paper_id=#{paperId})")
    int deleteByPaperId(@Param("paperId") Long paperId);

    @Select("SELECT question_id,a.answer user_answer,b.answer,answer_score user_score,type,title,content,`options`,score " +
            "FROM exam_answer a,question b " +
            "WHERE a.question_id = b.id AND a.exam_id = #{examId} AND a.user_id = #{userId} " +
            "ORDER BY type ASC,id ASC")
    List<Map<String, Object>> getUserExamAnswer(Long examId, Long userId);
}
